import data_loader

code_map1 = {}  # {1: "牛首生菜"}

code_map2 = {}  # {"102900005115168":1, ...}

code_to_type = {}  # {1:1,...} 意为牛首生菜对应花叶类

focus_products = [
    5,
    7,
    10,
    16,
    26,
    27,
    40,
    51,
    58,
    59,
    61,
    101,
    105,
    107,
    108,
    123,
    125,
    126,
    130,
    145,
    149,
    158,
    163,
    170,
    174,
    180,
    228,
    242,
    248,
]

focus2 = [
    5,
    6,
    7,
    10,
    15,
    16,
    19,
    25,
    26,
    27,
    34,
    40,
    51,
    58,
    59,
    61,
    101,
    105,
    107,
    108,
    110,
    119,
    123,
    125,
    126,
    130,
    134,
    145,
    149,
    158,
    163,
    170,
    171,
    174,
    176,
    177,
    180,
    215,
    219,
    228,
    231,
    242,
    248,
]

type_map1 = {
    1: "花叶类",
    2: "花菜类",
    3: "水生根茎类",
    4: "茄类",
    5: "辣椒类",
    6: "食用菌",
}
"""
1011010201,花菜类,15.51 2
1011010402,水生根茎类,13.65 3
1011010101,花叶类,12.83 1
1011010801,食用菌,9.45 6
1011010504,辣椒类,9.24 5
1011010501,茄类,6.68 4
"""

type_map2 = {
    "1011010101": 1,
    "1011010201": 2,
    "1011010402": 3,
    "1011010501": 4,
    "1011010504": 5,
    "1011010801": 6,
}

data = data_loader.load_data1()
for i in range(len(data)):
    x = data[i]
    code_map1[i + 1] = x["product_name"]
    code_map2[x["product_code"]] = i + 1
    code_to_type[i + 1] = type_map2[x["category_code"]]


def type_code_to_code(x):  # 10110101 to 1
    return type_map2[x]


def code_to_code(x):  # 102900005115168 to 1
    return code_map2[x]


def get_typename(x):  # 1 to 花菜类
    return type_map1[x]


def get_type(x):  # 1 to 1； 249 to 6
    return code_to_type[x]


def get_name(x):
    if int(x) > 500:
        return code_map1[code_map2[x]]
    return code_map1[x]


if __name__ == "__main__":
    print(code_map1[15])
